package com.lemon.springcloud.core.util;

import com.alibaba.fastjson.JSON;
import com.lemon.core.common.lang.util.StringUtils;
import com.lemon.springcloud.core.config.LemonSpringBootConfig;
import java.util.List;

/**
 * @author lemon
 * @ClassName RegisterComponentInfoUtils
 * @desc
 * @Date 2019/3/8 19:04
 * @Version 1.0
 **/
public class RegisterComponentInfoUtils {

    public static void registerRedisInfo(String redisGroupName, String host, Integer port, String password) {
        String redisProtocol = (StringUtils.isNotBlank(password) ? password + "@" : "") + "redis://" + host + ":" + port;
        LemonSpringBootConfig.addRedisGroupInfo(redisGroupName, redisProtocol);
    }

    public static void registerRabbitMQInfo(String rabbitmqGroupName, String host, Integer port, String userName, String password) {
        String rabbitmqProtocol = userName + "/" + password + "@rabbitmq://" + host + ":" + port;
        LemonSpringBootConfig.addRabbitmqGroupInfo(rabbitmqGroupName, rabbitmqProtocol);
    }

    public static void registerElasticsearchMQInfo(String elasticsearchGroupName, List<String> httpUrls) {
        String elasticsearchProtocol = JSON.toJSONString(httpUrls);
        LemonSpringBootConfig.addElasticsearchGroupInfoGroupInfo(elasticsearchGroupName, elasticsearchProtocol);
    }
}
